#include "widget.h"
#include "ui_widget.h"
#include <QString>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QRegularExpression regExp("^1\\d{10}$");
    ui->lineEdit->setValidator(new QRegularExpressionValidator(regExp));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_lineEdit_textEdited(const QString &arg1)
{
    QString arg = arg1;
    int pos = 0;
    // 判断输入的电话号码，基于正则表达式验证
    if(ui->lineEdit->validator()->validate(arg,pos) == QRegularExpressionValidator::Acceptable)
    {
        ui->pushButton->setEnabled(true);
    }
    else
    {
        ui->pushButton->setEnabled(false);
    }
}

